/************************************************************************/
/* GUI                                                                  */
/************************************************************************/
#include "GUI/TextMessages/BaseTextMessage.h"

namespace TD_GUI {

	/************************************************************************/
	/* ctors and dtors                                                      */
	/************************************************************************/
	BaseTextMessage::BaseTextMessage() : Tile() {
		
	}

	BaseTextMessage::BaseTextMessage(const BaseTextMessage &rhs) : Tile(rhs) {
		m_text = rhs.getText();
	}

	BaseTextMessage & BaseTextMessage::operator =(const BaseTextMessage &rhs) {
		BaseEntity::operator =(rhs);
		m_text = rhs.getText();
		return(*this);
	}

	BaseTextMessage::BaseTextMessage(const Coord2D &textPos, const string &initString, const string &fontSource, 
							unsigned int fontSize, const Color &fontColor, renderType g_renderType) : Tile(textPos) {
		m_text = initString;
		m_position = textPos;
		m_renderType = g_renderType;
		m_fontColor.r = fontColor.red;
		m_fontColor.g = fontColor.green;
		m_fontColor.b = fontColor.blue;
		m_fontColor.unused = fontColor.alpha;
		m_pFont = TD_Resources::ResourceManager::loadFont(fontSource, fontSize);
		setText(m_text);
	}

	BaseTextMessage::~BaseTextMessage() {
		
	}

	void BaseTextMessage::setText(const string & text)  {
		m_text = text;
		if(m_pImage == NULL) {
			m_pImage = shared_ptr<SDLImage>(new SDLImage());
		}		
		
		switch(m_renderType) {
				case textSolid:
					m_pImage->setSurface(TTF_RenderText_Solid(m_pFont->getRawFont(), m_text.c_str(), m_fontColor));
					if(m_fontColor.unused >= 0) {
						SDL_SetAlpha(m_pImage->getSurface(), SDL_SRCALPHA | SDL_RLEACCEL, m_fontColor.unused); 
					}
					break;

				case textShaded:
					/*m_pImage->setSurface(TTF_RenderText_Shaded(m_pFont->getRawFont(), m_text.c_str(), m_fontColor));*/
					break;

				case textBlended:
					m_pImage->setSurface(TTF_RenderText_Blended(m_pFont->getRawFont(), m_text.c_str(), m_fontColor));
					break;
		}
	}


	/************************************************************************/
	/* Rendering                                                            */
	/************************************************************************/
	
	void BaseTextMessage::render(SDL_Surface *const g_destSurface, unsigned int deltaTime) {
		blitSurface(g_destSurface);
	}
}